 
use "$path\datasets\rd_dataset.dta", clear
keep if in_rdd_sample==1



gen close_female=(margin_1<=0.05 & margin_1>=0) if margin_1<.
gen close_male=(margin_1>=-0.05 & margin_1<0) if margin_1<.
gen non_close_female=(margin_1>0.05 & margin_1<.) if margin_1<.
gen non_close_male=(margin_1<-0.05) if margin_1<.



 
ivreg csu margin_1 , r cluster(gkz)
est store m1
sum csu if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg spd  margin_1, r cluster(gkz)
est store m2
sum spd if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg greens margin_1 , r cluster(gkz)
est store m3
sum greens if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg higher_degree margin_1 , r cluster(gkz)
est store m4
sum higher_degree if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg employed margin_1 , r cluster(gkz)
est store m5
sum employed if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg  selfemployed margin_1 , r cluster(gkz)
est store m6
sum selfemployed if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  student margin_1 , r cluster(gkz)
est store m7
sum student if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  retired margin_1 , r cluster(gkz)
est store m8
sum retired if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg  alter margin_1 , r cluster(gkz)
est store m9
sum alter if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)









esttab  m1 m2 m3 m4 m5 m6 m7 m8 m9 using TableA27/tableA27_PanelB.txt, replace order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
  keep (margin_1   ) ///
  stats( N   N_clust mean_depvar sd_depvar , layout( @  @  `""@ (@)""' )  fmt(  %9.0g %9.0g  %9.2f %9.2f  ) ///
 labels(  "N"  "Municipalities" "Mean (SD)"  )) ///
starlevels(* 0.10 ** 0.05 *** 0.01) ///
  indicate( ) style(tab) ///
  varlabels(  margin_1 "Margin of victory of female candidate")



************************************************************************************************************************************


